class Solution {
public:
    int findClosestNumber(vector<int>& nums) {
        int dis = abs(nums[0]), ans = nums[0];
        for (int i = 1; i < nums.size(); i++) {
            if (abs(nums[i]) < dis) {
                dis = abs(nums[i]);
                ans = nums[i];
            } else if (abs(nums[i]) == dis) {
                ans = max(ans, nums[i]);
            }
        }
        return ans;
    }
};
